package com.atguigu.utils;

import java.util.Arrays;
import java.util.Comparator;

//所谓方法引用，是指如果某个方法签名和接口恰好一致，就可以直接传入方法引用。
public class MethodRefDemoV2 {
    static int cmp0923(String s1,String s2){
        return s1.compareTo(s2);
    }

    public static void main(String[] args) {
        String[] array = {"Apple", "Orange", "Banana", "Lemon"};

        //v1匿名内部类,new接口
        Arrays.sort(array, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.compareTo(o2);
            }
        });

        //v3方法引用，专门替代lambdaExpress
        Arrays.sort(array,MethodRefDemoV2::cmp0923);

        //v2 lambdaExpression
        Arrays.sort(array,(o1,o2)->o1.compareTo(o2));

        System.out.println(String.join(",", array));

    }

}
